<?php
/* 选修课各分数等级及人数统计 */
class DefaultController extends FController {
	
	public function init() {
		parent::init ();
		$this->commonScript ();
		Yii::app ()->clientScript->registerCssFile ( THEME_CSS_URL . '/base.css' );
		Yii::app ()->clientScript->registerCssFile ( THEME_CSS_URL . '/master.css' );
		Yii::app ()->clientScript->registerCssFile ( THEME_CSS_URL . '/module_Sip.css' );
	}
	public function __common() {
		parent::init ();
		if (empty ( $this->cLoginUser )) {
			$this->redirect ( $this->createUrl ( '/site/login' ) );
		}
		
		$this->commonScript ();
		Yii::app ()->clientScript->registerCssFile ( THEME_CSS_URL . '/module_Sip.css' );
	}
	
	/**
	 * @ 首页
	 * @ yindebin
	 * @ 2013-12-15
	 */
	
	public function actionIndex() {
		$this->__common ();
		$this->title = "选修课各等级分数及人数统计";
		#  取考试项目  #
		$exam = new ExamData ();
		$list ['exam'] = $exam->_getExam ();
		
		#  取学校  #
		$list ['school'] = $exam->_getSchool ();
		
		$this->render ( 'index', array ('list' => $list ) );
	}
	
	/**
	 * @ 选课课统计信息
	 * @ yindebin
	 * @ 2013-12-15
	 */
	
	public function actionScore_count() {
		$this->__common ();
		$this->layout = "//layouts/main_other";
		Yii::app ()->clientScript->registerScriptFile ( STATICS_URL . "/js/Highcharts/js/highcharts.js" );
		Yii::app ()->clientScript->registerScriptFile ( STATICS_URL . "/js/Highcharts/js/modules/exporting.js" );
		
		$exam_id = (! empty ( $_POST ['exam'] )) ? $_POST ['exam'] : 0;
		$school_id = (! empty ( $_POST ['school'] )) ? $_POST ['school'] : 0;
		
		if (empty ( $exam_id ) && empty ( $school_id )) {
			echo "<script>alert('数据不完整');</script>";
			echo "<script>window.close();</script>";
		}
		
		
		#  取考试项目的科目  #
		$exam = new ExamData ();
		$subject_data = $exam->_getExamSubject ( $exam_id );
		
		if(empty($subject_data)){
			echo "<script>alert('不存在考试相关的科目数据');</script>";
			echo "<script>window.close();</script>";
		}
		
		if(empty($school_id)){
			$school_data = $exam->_getExamSchool($exam_id);
			if(!empty($school_data)){
				$school_id = '';
				foreach ($school_data as $value){
					$school_id .= $value['school_id'].',';
				}
				$school_id = substr($school_id, 0,  -1);
			}else{
				echo "<script>alert('不存在的学校数据');</script>";
				echo "<script>window.close();</script>";
			}
		}
		
		#  取所有的分数等级  #
		$grading = $exam->_getGrading ();
		if(empty($grading)){
			echo "<script>alert('不存在的等级设置');</script>";
			echo "<script>window.close();</script>";
		}
		
		$point = $array = array ();
		if (! empty ( $subject_data )) {
			
			
			foreach ( $subject_data as $key => $value ) {
				#  取分数   #  school_id exam_id  subject_id
				$point [$value ['subject_id']] ['point'] = $exam->_getExamPoint ( $value ['subject_id'], $school_id, $exam_id );

				$subject_data [$key] ['count'] = count ( $point [$value ['subject_id']] ['point'] );
				
				#  取分数段设置   # $exam_id $subject_id
				$point [$value ['subject_id']] ['grading_data'] = array ();
				
				$array = $exam->_getPointGrading ( $value ['subject_id'], $exam_id );
				if (! empty ( $array )) {
					foreach ( $array as $av ) {
						$point [$value ['subject_id']] ['grading_data'] ['score' . $av ['grading_id']] ['grading_id'] = $av ['grading_id'];
						$point [$value ['subject_id']] ['grading_data'] ['score' . $av ['grading_id']] ['score'] = $av ['score'];
						$point [$value ['subject_id']] ['grading_data'] ['score' . $av ['grading_id']] ['grading_name'] = $av ['grading_name'];
					}
				}
				
				#  统计各科各分数段的人数   #
				

				if (! empty ( $point [$value ['subject_id']] ['grading_data'] )) {
					foreach ( $point [$value ['subject_id']] ['grading_data'] as $pv ) {
						$temp = 0;
						foreach ( $point [$value ['subject_id']] ['point'] as $gpv ) {
							if ($pv ['score'] <= $gpv ['score']) {
								$temp ++;
							}
						}
						$point [$value ['subject_id']] ['sum' . $pv ['grading_id']] = $temp;
					}
				}
				unset ( $point [$value ['subject_id']] ['point'] );
			}
		}
		
		$this->render ( 'score_sum', array ('point' => $point, 'grading' => $grading, 'subject' => $subject_data ) );
	}
	
	/**
	 * @ 取参加考试的学校
	 * @ yindebin
	 * @ 2013-12-15
	 */
	public function actionAjax_school() {
		$exam_id = ( int ) Yii::app ()->request->getParam ( 'exam_id' );
		
		$str = " <select class='fl fontc_666' name='school'> <option value='0'>选择学校</option>";
		
		if (! empty ( $exam_id )) {
			
			$exam = new ExamData ();
			$school = $exam->_getExamSchool ( $exam_id );
			if (! empty ( $school )) {
				foreach ( $school as $value ) {
					$str .= "<option value='" . $value ['school_id'] . "'>" . $value ['school_name'] . "</option>";
				}
			}
		
		}
		echo $str;
		exit ();
	}
	
	/**
	 * @ 高中总分分数段
	 * @ yindebin
	 * @ 2013-12-15
	 */
	
	public function actionPoints_grading() {
		$this->__common ();
		$this->title ='(高中)总分分数段统计';
		#  取考试项目  #
		$exam = new ExamData ();
		$list ['exam'] = $exam->_getExam ();
		
		#  取学校  #
		$list ['school'] = $exam->_getSchool ();
		
		$this->render ( 'point_grading', array ('list' => $list ) );
	}
	
	/**
	 * @ 高中总分分数段报表
	 * @ yindebin
	 * @ 2013-12-15
	 */
	
	public function actionPoints_grading_count() {
		$this->__common ();
		$this->layout = "//layouts/main_other";
		Yii::app ()->clientScript->registerScriptFile ( STATICS_URL . "/js/Highcharts/js/highcharts.js" );
		Yii::app ()->clientScript->registerScriptFile ( STATICS_URL . "/js/Highcharts/js/modules/exporting.js" );
		
		$up = (! empty ( $_POST ['up'] )) ? $_POST ['up'] : 500;
		$down = (! empty ( $_POST ['up'] )) ? $_POST ['down'] : 10;
		$inter = (! empty ( $_POST ['inter'] )) ? $_POST ['inter'] : 10;
		$school_id = (! empty ( $_POST ['school'] )) ? $_POST ['school'] : 0;
		$exam_id = (! empty ( $_POST ['exam'] )) ? $_POST ['exam'] : 0;
		$subject_type = (! empty ( $_POST ['subject_type'] )) ? $_POST ['subject_type'] : 0;
		
		if (! is_numeric ( $up ) || ! is_numeric ( $down ) || ! is_numeric ( $inter )) {
			
			$this->runShowMessge("points_grading",'您选择的数据不完整');
		}
		
		#  取学校代码   #
		$examObject = new ExamData ();
		if (! empty ( $school_id )) {
			$school_info = $examObject->_getSchool ( $school_id );
			$school_code = (! empty ( $school_info )) ? $school_info ['school_code'] : '';
		}
	
		#  取学生  #
		if (! empty ( $school_code )) {
			$student_data = $examObject->_getStuden ( $exam_id, $subject_type, $school_code );
		} else {
			$student_data = $examObject->_getStuden ( $exam_id, $subject_type );
		}
		
		#  取成绩   #
		if (! empty ( $student_data )) {
			$score_array = $array = array ();
			foreach ( $student_data as $key => $value ) {
				$temp = $examObject->_getStudentPoint ( $exam_id, $value ['student_id'] );
				$student_data [$key] ['score_sum'] = (! empty ( $temp ['score_sum'] )) ? $temp ['score_sum'] : 0;
				
				if (empty ( $school_code )) {
					# 分数   #
					$score_array [$value ['school_code']] [] = $student_data [$key] ['score_sum'];
					
					#  人数   #
					if (! isset ( $array [$value ['school_code']] ['student_num'] )) {
						$array [$value ['school_code']] ['student_num'] = 1;
					} else {
						$array [$value ['school_code']] ['student_num'] ++;
					}
					
					#  最高分   #
					if (isset ( $array [$value ['school_code']] ['max_score'] )) {
						if ($temp ['score_sum'] > $array [$value ['school_code']] ['max_score']) {
							$array [$value ['school_code']] ['max_score'] = $temp ['score_sum'];
						}
					} else {
						$array [$value ['school_code']] ['max_score'] = $temp ['score_sum'];
					}
					
					
					#  取学校  #  school_code
					if (empty ( $array [$value ['school_code']] ['school_data'] )) {
						$array [$value ['school_code']] ['school_data'] = $school_data [] = $examObject->_getCodeSchool ( $value ['school_code'] );
					}
					
				
				} else {
					#  分数   #
					$score_array [$school_code] [] = $student_data [$key] ['score_sum'];
					
					#  人数   #
					if (! isset ( $array [$school_code] ['student_num'] )) {
						$array [$school_code] ['student_num'] = count ( $student_data );
					}
					
					#  最高分   #
					if (isset ( $array [$school_code] ['max_score'] )) {
						if ($temp ['score_sum'] > $array [$school_code] ['max_score']) {
							$array [$school_code] ['max_score'] = $temp ['score_sum'];
						}
					} else {
						$array [$school_code] ['max_score'] = $temp ['score_sum'];
					}
					
					#  取学校  #  school_code
					if (! isset ( $school_data )){
					
						$school_data [] = $examObject->_getCodeSchool ( $value ['school_code'] );
					}
						
						
				}
			}
		
	
			#  处理学校相关数据  #
			foreach ( $school_data as $key => $value ) {
				$school_data [$key] ['max_score'] = (! empty ( $array [$value ['school_code']] ['max_score'] )) ? $array [$value ['school_code']] ['max_score'] : 0;
				$school_data [$key] ['student_num'] = (! empty ( $array [$value ['school_code']] ['student_num'] )) ? $array [$value ['school_code']] ['student_num'] : 0;
				$school_data [$key] ['score_array'] = (!empty($value['school_code'])) ? $score_array [$value ['school_code']] : array();
				
			}
			
			#  整理分数上下限数据   #
			$point_array = array ();
			$i = 0;
			do {
				$point_array [] ['point'] = $up;
				$up = ($up - $inter);
				$i ++;
			} while ( $up >= $down );
			$point_down = $point_array [$i - 1] ['point'];
			
			#  取本一本二分数线   #
			$edu_score = $examObject->_getEduScore ( $exam_id, $subject_type );
			$xData[] = '本一 线('.$edu_score['score_type1'].')';
			$xData[] = '本二线('.$edu_score['score_type2'].')';
			
			# 划分分数段   #			

			foreach ( $school_data as $sk => $sv ) {
				foreach ( $sv ['score_array'] as $skey => $svalue ) {
					foreach ( $point_array as $key => $value ) {
						if ($svalue >= $value ['point']) {
							
							if (isset ( $school_data [$sk] [$key] )) {
								
								$school_data [$sk] [$key] ++;
							
							} else {
								
								$school_data [$sk] [$key] = 1;
							
							}
						}
					}
					#  本一   #
					if(!empty($edu_score)){
						if ($svalue >= $edu_score ['score_type1']) {
							if (isset ( $school_data [$sk] ['yiben'] )) {
								$school_data [$sk] ['yiben'] ++;
							} else {
								$school_data [$sk] ['yiben'] = 1;
							}
						}
						if ($svalue >= $edu_score ['score_type2']) {
							if (isset ( $school_data [$sk] ['erben'] )) {
								$school_data [$sk] ['erben'] ++;
							} else {
								$school_data [$sk] ['erben'] = 1;
							}
						}
					}else{
						$school_data [$sk] ['erben'] = $school_data [$sk] ['yiben'] = '未设置';
					}
				}
			}
			#  取最低分数段人数及本线人数    #
			foreach ( $school_data as $key => $value ) {
				$school_data [$key] ['point_down_num'] = (! empty ( $value [$i - 1] )) ? $value [$i - 1] : 0;
			}
		}else{
			$this->runShowMessge("points_grading",'没有可统计的数据');
			exit;
		}
	
		
		$this->render ( 'point_grading_count', array ('school_data' => $school_data, 'point_array' => $point_array, 'point_down' => $point_down ,'xData1'=>json_encode($xData),) );
	}
	
	/**
	 * @ 总分及三门平均分 
	 * @ yindebin
	 * @ 2013-12-16
	 */
	
	public function actionTotal_point(){
		$this->__common ();
		$this->title='总分及三门平均分统计';
		#  取考试项目  #
		$exam = new ExamData ();
		$list ['exam'] = $exam->_getExam ();
		
		#  取地区  #
		$list ['region'] = $exam->_getRegion ();
		
		$this->render ( 'total_point', array ('list' => $list ) );
	}
	
	/**
	 * @ 总分及三门平均分 统计
	 * @ yindebin
	 * @ 2013-12-16
	 */
	
	public function actionTotal_point_count(){
		$this->__common ();
		$this->layout = "//layouts/main_other";
		Yii::app ()->clientScript->registerScriptFile ( STATICS_URL . "/js/Highcharts/js/highcharts.js" );
		Yii::app ()->clientScript->registerScriptFile ( STATICS_URL . "/js/Highcharts/js/modules/exporting.js" );
		
		$exam_id = Yii::app()->request->getParam('exam_id');
		$region_id = Yii::app()->request->getParam('region_id');
		
		if(empty($region_id) || empty($exam_id)){
			$this->runShowMessge("total_point",'您选择的数据不完整');
		}
		
		# 取语数外ID,没有不让统计   #
		$sql = "SELECT subject_id FROM {{subject}} WHERE subject_name = '语文' OR subject_name = '数学' OR subject_name = '英语'";
		$result = Yii::app()->db->createCommand($sql)->queryAll();
		if(empty($result[0]['subject_id']) || empty($result[1]['subject_id']) || empty($result[2]['subject_id']))
			$this->redirect($this->createUrl('index'));
			
		$ID['yu_id'] = $result[0]['subject_id'];
		$ID['shu_id'] = $result[1]['subject_id'];
		$ID['ying_id'] = $result[2]['subject_id'];
		
		#  取二级所有地区   #
		$exam = new ExamData ();
		$region = $exam->_getRegion($region_id);
		
		#  取所有学生人数  #
		
		$school_data = $exam->_getRegionSchool($region_id);  // 学校
		
		
		$tj['num'] = $tj['lzcount'] = $tj['li_num'] = $tj['li_count'] = $tj['wen_num'] = $tj['wen_count'] = 0;
		$tj['liyu_num'] = $tj['liyu_count'] = $tj['wenyu_num'] = $tj['wenyu_count'] = 0;
		$tj['lishu_num'] = $tj['lishu_count'] = $tj['wenshu_num'] = $tj['wenshu_count'] = 0;
		$tj['liying_num'] = $tj['liying_count'] = $tj['wenying_num'] = $tj['wenying_count'] = 0;
		if (!empty($school_data)){
			foreach ($school_data as $k=>$v){
				// zong
				$sql = "SELECT COUNT(*) AS student_num,SUM(score) AS score_count FROM {{point}} WHERE exam_id = '".$exam_id."' AND school_id = '".$v['school_id']."'";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['num'] = ($temp['student_num'] + $tj['num']);
				$tj['lzcount'] = ($temp['score_count'] + $tj['lzcount']);
				
				 // li
				$sql = "SELECT COUNT(*) AS li_student_num,SUM(score) AS li_score_count FROM {{point}} WHERE exam_id = '".$exam_id."' AND school_id = '".$v['school_id']."' AND disciplin_id = 1";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['li_num'] = ($temp['li_student_num'] + $tj['li_num']);
				$tj['li_count'] = ($temp['li_score_count'] + $tj['li_count']);
								
				 // wen
				$sql = "SELECT COUNT(*) AS wen_student_num,SUM(score) AS wen_score_count FROM {{point}} WHERE exam_id = '".$exam_id."' AND school_id = '".$v['school_id']."' AND disciplin_id = 2";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['wen_num'] = ($temp['wen_student_num'] + $tj['wen_num']);
				$tj['wen_count'] = ($temp['wen_score_count'] + $tj['wen_count']);
				
				// liyu
				$sql = "SELECT COUNT(*) as student_num,SUM(score) AS score_count FROM {{point}} WHERE exam_id ='".$exam_id."' AND school_id = '".$v['school_id']."' AND disciplin_id = '1' AND subject_id = '".$ID['yu_id']."'";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['liyu_num'] = ($temp['student_num'] + $tj['liyu_num']);
				$tj['liyu_count'] = ($temp['score_count'] + $tj['liyu_count']);
				
				// wenyu
				$sql = "SELECT COUNT(*) as student_num,SUM(score) AS score_count FROM {{point}} WHERE exam_id ='".$exam_id."' AND school_id = '".$v['school_id']."' AND disciplin_id = '2' AND subject_id = '".$ID['yu_id']."'";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['wenyu_num'] = ($temp['student_num'] + $tj['wenyu_num']);
				$tj['wenyu_count'] = ($temp['score_count'] + $tj['wenyu_count']);
				
				// lishu
				$sql = "SELECT COUNT(*) as student_num,SUM(score) AS score_count FROM {{point}} WHERE exam_id ='".$exam_id."' AND school_id = '".$v['school_id']."' AND disciplin_id = '1' AND subject_id = '".$ID['shu_id']."'";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['lishu_num'] = ($temp['student_num'] + $tj['lishu_num']);
				$tj['lishu_count'] = ($temp['score_count'] + $tj['lishu_count']);
				
				// wenshu
				$sql = "SELECT COUNT(*) as student_num,SUM(score) AS score_count FROM {{point}} WHERE exam_id ='".$exam_id."' AND school_id = '".$v['school_id']."' AND disciplin_id = '2' AND subject_id = '".$ID['shu_id']."'";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['wenshu_num'] = ($temp['student_num'] + $tj['wenshu_num']);
				$tj['wenshu_count'] = ($temp['score_count'] + $tj['wenshu_count']);
				
				// liying
				$sql = "SELECT COUNT(*) as student_num,SUM(score) AS score_count FROM {{point}} WHERE exam_id ='".$exam_id."' AND school_id = '".$v['school_id']."' AND disciplin_id = '1' AND subject_id = '".$ID['ying_id']."'";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['liying_num'] = ($temp['student_num'] + $tj['liying_num']);
				$tj['liying_count'] = ($temp['score_count'] + $tj['liying_count']);
				
				// wenying
				$sql = "SELECT COUNT(*) as student_num,SUM(score) AS score_count FROM {{point}} WHERE exam_id ='".$exam_id."' AND school_id = '".$v['school_id']."' AND disciplin_id = '2' AND subject_id = '".$ID['ying_id']."'";
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$tj['wenying_num'] = ($temp['student_num'] + $tj['wenying_num']);
				$tj['wenying_count'] = ($temp['score_count'] + $tj['wenying_count']);	
			}
		}

		
		#   各地区人数  #
		if (!empty($region)){
			foreach ($region as $k=>$v){
				$sql = " SELECT COUNT(*) AS student_nums FROM {{school}} AS a LEFT JOIN {{point}} AS b ON a.school_id = b.school_id WHERE a.region_id = '".$v['id']."' AND b.exam_id = '".$exam_id."'";
				
				$temp = Yii::app()->db->createCommand($sql)->queryRow();
				$region[$k]['student_nums'] = $temp['student_nums'];
				
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['student_num'] = $temp['student_nums'];
				$region[$k]['score_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				// lizong
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."' AND disciplin_id = '1'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['li_num'] = $temp['student_nums'];
				$region[$k]['li_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				// wenzong
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."'  AND disciplin_id = '2'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['wen_num'] = $temp['student_nums'];
				$region[$k]['wen_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				// liyu
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."'  AND disciplin_id = '1' AND subject_id = '".$ID['yu_id']."'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['liyu_num'] = $temp['student_nums'];
				$region[$k]['liyu_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				//wenyu
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."'  AND disciplin_id = '2' AND subject_id = '".$ID['yu_id']."'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['wenyu_num'] = $temp['student_nums'];
				$region[$k]['wenyu_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				//lishu
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."'  AND disciplin_id = '1' AND subject_id = '".$ID['shu_id']."'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['lishu_num'] = $temp['student_nums'];
				$region[$k]['lishu_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				//wenshu
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."'  AND disciplin_id = '2' AND subject_id = '".$ID['shu_id']."'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['wenshu_num'] = $temp['student_nums'];
				$region[$k]['wenshu_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				//liying
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."'  AND disciplin_id = '1' AND subject_id = '".$ID['ying_id']."'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['liying_num'] = $temp['student_nums'];
				$region[$k]['liying_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				//wenying
				$ssql = "SELECT COUNT(*) AS student_nums,SUM(a.score) AS score_counts FROM {{point}} AS a LEFT JOIN {{school}} AS b ON a.school_id = b.school_id WHERE b.region_id = '".$v['id']."' AND a.exam_id = '".$exam_id."'  AND disciplin_id = '2' AND subject_id = '".$ID['ying_id']."'";
				$temp = Yii::app()->db->createCommand($ssql)->queryRow();
				
				$region[$k]['wenying_num'] = $temp['student_nums'];
				$region[$k]['wenying_count'] = (!empty($temp['score_counts'])) ? $temp['score_counts'] : 0 ;
				
				
			}
		}
		$this->render('total_point_count',array(
			'tongji'	=> $tj,
			'region'	=> $region,
		));		
	}
	
}
